// import VueI18n from '@/utils/js/vue-i18n.min.js';
import {createI18n } from 'vue-i18n'
const langFiles = require.context("./config", false, /\.js$/);
//正则用于匹配 ./en.js中的'en'
let regExp = /\.\/([^\.\/]+)\.([^\.]+)$/ 
//声明一个数据模型，对应i18n中的message属性
const messages = {} 

langFiles.keys().forEach(key => {
    let prop = regExp.exec(key)[1]
    //messages['en'] = {table:{...}}
    messages[prop] = langFiles(key).default
})

let locale = localStorage.getItem('lang')||"zh-CN";

const localeData  = {
    legacy: false, // composition API
    locale,
    messages
}
export default {
    install(app){
        const i18n = createI18n(localeData);
        app.use(i18n);
        app.config.globalProperties.$i18n=i18n;
    }
}